﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
using System.Xml;
using My.SharePoint.STSADM.Commands.OperationHelpers;
using My.SharePoint.STSADM.Commands.SPValidators;
using IdeasFree.SharePoint.StsAdm.Commands.Helpers;

namespace IdeasFree.SharePoint.StsAdm.Commands
{
    public class ImportDocument : SPOperation
    {
        
        public ImportDocument()
        {
            SPParamCollection parameters = new SPParamCollection();
            parameters.Add(new SPParam("url", "url", true, null, new SPUrlValidator(), "Please specify url of the site."));
            parameters.Add(new SPParam("doclib", "doclib", true, null, new SPNonEmptyValidator(), "Please specify target document library."));
            parameters.Add(new SPParam("importfolder", "importfolder", true, null, new SPNonEmptyValidator(), "Please specify path to exported documents."));
            parameters.Add(new SPParam("mapping", "mapping", true, null, new SPNonEmptyValidator(), "Field mapping configuration."));
            parameters.Add(new SPParam("metaonly", "metaonly", false, "true", new SPTrueFalseValidator(), "Please specify True or False"));

            StringBuilder sb = new StringBuilder();
            sb.Append("-url <full url to a which host the document library> ");
            sb.Append("\r\n\t-doclib <document library name to be exported> ");
            sb.Append("\r\n\t-importfolder <path to the folder to store exported documents> ");
            sb.Append("\r\n\t-mapping <mapping configuration file> ");
            sb.Append("\r\n\t-metaonly <Default: true , export only the metadata> ");

            sb.Append("\r\n\r\nImport whole structue of document library from a physical folder, with mapping metadata.");
            Init(parameters, sb.ToString());
        }


        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            ImportDocumentOperation ops = new ImportDocumentOperation(Params, keyValues);
            ops.Process();
            
            output = "";
            return 1;
        }



        public override string GetHelpMessage(string command)
        {
            return HelpMessage;
        }

     
    }
}
